package beautiful.butterfly.distributed_task_processing_engine.task_manage.task_processor;

import beautiful.butterfly.distributed_task_processing_engine.task_manage.task_data_items_processor.task_data_item_data_manager.ITaskAndTaskProcessorAndTaskDataItemManage;
import beautiful.butterfly.distributed_task_processing_engine.tools.Constants;
import beautiful.butterfly.distributed_task_processing_engine.tools.Group;
import beautiful.butterfly.distributed_task_processing_engine.tools.LocalHostAddress;
import beautiful.butterfly.distributed_task_processing_engine.tools.Uuids;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;

import java.sql.Timestamp;

public class TaskProcessorInfo
{
    @Group("物理机信息")
    @SerializedName("ip")
    @Setter
    @Getter
    public String ip;
    @SerializedName("hostName")
    @Setter
    @Getter
    public String hostName;
    @SerializedName("jvmInstanceId")
    @Setter
    @Getter
    public String jvmInstanceId;
    //
    @Group("任务信息")
    @SerializedName("taskId")
    @Setter
    @Getter
    public String taskId;
    @SerializedName("nextRunStartTime")
    @Setter
    @Getter
    public String nextRunStartTime;
    @SerializedName("nextRunEndTime")
    @Setter
    @Getter
    public String nextRunEndTime;
    @SerializedName("threadNum")
    @Setter
    @Getter
    public int threadNum;
    //
    @Group("注册信息")
    @SerializedName("taskProcessorId")
    @Setter
    @Getter
    public String taskProcessorId;
    @SerializedName("isRegister")
    @Setter
    @Getter
    public boolean isRegister;
    @SerializedName("registerTimestamp")
    @Setter
    @Getter
    public Timestamp registerTimestamp;
    //
    @Group("心跳信息")
    @SerializedName("leaderTaskProcessorTimestamp")
    @Setter
    @Getter
    public Timestamp leaderTaskProcessorTimestamp;
    @SerializedName("heartBeatTimestamp")
    @Setter
    @Getter
    public Timestamp heartBeatTimestamp;
    @SerializedName("version")
    @Setter
    @Getter
    public long version;
    //
    @Group("处理过程信息")
    @SerializedName("lastFetchDataTimestamp")
    @Setter
    @Getter
    public Timestamp lastFetchDataTimestamp;
    /**
     * FetchDataCount=4430,FetcheDataNum=438570,DealDataSucess=438570,DealDataFail=0,DealSpendTime=651066
     */
    @SerializedName("dealInfoDesc")
    @Setter
    @Getter
    public String dealInfo;
    //


    public static TaskProcessorInfo createTaskProcessorInfo(//
                                                            ITaskAndTaskProcessorAndTaskDataItemManage taskDataManager, //
                                                            String jvmInstanceId,
                                                            String scheduleTaskId,//
                                                            int threadNum)//
            throws Exception
    {
        TaskProcessorInfo taskProcessorInfo = new TaskProcessorInfo();
        //
        taskProcessorInfo.ip = LocalHostAddress.getLocalHostAddress();
        taskProcessorInfo.hostName = LocalHostAddress.getLocalHostName();
        taskProcessorInfo.jvmInstanceId = jvmInstanceId;
        //
        taskProcessorInfo.taskId = scheduleTaskId;
        taskProcessorInfo.threadNum = threadNum;
        //
        taskProcessorInfo.taskProcessorId = taskProcessorInfo.ip + Constants.$ + (Uuids.getUuid());//在注册的时候修正
        //
        taskProcessorInfo.registerTimestamp = new Timestamp(taskDataManager.zooKeeperCurrentTimeMillis());
        taskProcessorInfo.heartBeatTimestamp = null;
        taskProcessorInfo.version = 0;
        //
        taskProcessorInfo.dealInfo = "";


        return taskProcessorInfo;
    }
}
